package com.china08.yxyapi.api.manage.sch.platform.xiaoben.auth;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.model.YxyApiPageReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.service.db.UserAuthService;

@CrossOrigin
@RestController
public class UserAuthStudentIdAuthedController extends YxyApiBaseController {

    @Autowired
    UserAuthService authService;

    @RequestMapping(value = "/api_yw/manage/sch/xiaoben/auth/user/studentid/authed/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public List<RespModel> process(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel) {
        String schoolId = getProfile(request, response).getSchoolId();
        String classId = reqModel.classId;

        List<RespModel> list = new ArrayList<RespModel>();

        List<Map<String, Object>> l = authService.authStudentIdList(schoolId, classId);
        for (Map<String, Object> map : l) {
            RespModel respModel = new RespModel();
            respModel.userId = map.get("user_id") + "";
            list.add(respModel);
        }
        return list;
    }

    public static class ReqModel extends YxyApiPageReqModel {
        public String classId;
    }

    public static class RespModel extends YxyApiRespModel {
        public String userId;
    }
}
